/*
 * @Author: 深海有鱼 847094299@qq.com
 * @Date: 2025-04-03 22:50:19
 * @LastEditors: 深海有鱼 847094299@qq.com
 * @LastEditTime: 2025-04-03 22:50:27
 * @FilePath: \pure-admin-thin\src\api\paymentApi.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { http } from "@/utils/http";

/** 分页获取当前用户的支付订单列表 */
export const getUserPayments = (params?: {
  page?: number;
  size?: number;
  status?: string;
}) => {
  return http.request<any>("get", "/api/payments", { params });
};

/** 创建支付订单（充值积分） */
export const createPayment = (data: object) => {
  return http.request<any>("post", "/api/payments", { data });
};

/** 主动同步订单状态 */
export const syncOrderStatus = (orderNo: string) => {
  return http.request<any>("post", `/api/payments/${orderNo}/sync`);
};

/** 为已过期或失败的订单重新创建支付订单 */
export const recreateExpiredOrder = (orderNo: string) => {
  return http.request<any>("post", `/api/payments/${orderNo}/recreate`);
};

/** 取消待支付订单 */
export const cancelPayment = (orderNo: string) => {
  return http.request<any>("post", `/api/payments/${orderNo}/cancel`);
};

/** 创建部分支付（适用于部分支付场景） */
export const createPartialPayment = (data: object) => {
  return http.request<any>("post", "/api/payments/partial", { data });
};

/** 根据订单号获取订单详情 */
export const getPaymentDetail = (orderNo: string) => {
  return http.request<any>("get", `/api/payments/${orderNo}`);
};

/** 获取支付订单的二维码（支付地址二维码图片） */
export const getPaymentQrCode = (orderNo: string) => {
  return http.request<any>("get", `/api/payments/${orderNo}/qrcode`);
};

/** 获取用户积分流水记录 */
export const getPointsRecords = (params?: {
  page?: number;
  size?: number;
  type?: string;
}) => {
  return http.request<any>("get", "/api/payments/points/records", { params });
};

/** 获取当前用户积分余额 */
export const getPointsBalance = () => {
  return http.request<any>("get", "/api/payments/points/balance");
};
